package com.szholly.pro.watergas_server.ps.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.RowBase;

/**
 * 用户service
 * @author gislin
 * 2016年8月15日
 */
@Service
public class UserService {

	/**
	 * 获取人员id
	 * gislin
	 * 2016年8月24日
	 * @param userName
	 * @return
	 */
	public String getUserIdByUserName(String userName){
		String sql = " select t.s_userid from safe_user t where t.c_username = @username ";
		List<GlobalParameter> pc = new ArrayList<GlobalParameter>();
		pc.add(new GlobalParameter("username", userName));
		
		String userId = DataUtil.getScale(sql, pc)+"";
		return userId;
	}
	
	/**
	 * 获取用户的功能
	 * gislin
	 * 2016年8月24日
	 * @param userId
	 * @return
	 */
	public List<RowBase> getUserFunctionByUserId(String userId){
		String sql = "select t2.c_functionbh from safe_rolefunction t\n" +
						"       left join safe_userrole t1 on t.s_roleid = t1.s_roleid\n" + 
						"       left join safe_function t2 on t2.s_functionid = t.s_functionid\n"+
						"       where t1.s_userid = @userId ";
		List<GlobalParameter> pc = new ArrayList<GlobalParameter>();
		pc.add(new GlobalParameter("userId", userId));
		
		List<RowBase> result = DataUtil.getSelectRows(sql, pc);
		return result;
	}
	
}
